package com.leyou.trade.web;

import com.leyou.trade.dto.PayResultDTO;
import com.leyou.trade.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayService payService;

    @GetMapping("/url/{id}")
    public ResponseEntity<String> generatePayCode(@PathVariable("id")Long orderId){

        return ResponseEntity.ok(this.payService.generatePayCode(orderId));
    }


    /**
     * 查询订单的付款状态
     * @param id
     * @return
     */
    @GetMapping("/status/{id}")
    public ResponseEntity<Integer> queryPayStatus(@PathVariable("id")Long id){
        return ResponseEntity.ok(this.payService.queryPayStatus(id));
    }

    /**
     * 微信回调
     * produces 生成的数据结构为xml
     * @param result
     * @return
     */
    @PostMapping(value = "/wx/notify",produces = MediaType.APPLICATION_XML_VALUE)
    public ResponseEntity<PayResultDTO> handNotify(
            @RequestBody Map<String,String> result){

        System.out.println("result = " + result);
        return ResponseEntity.ok(new PayResultDTO());
    }
}
